package ro.ubbcluj.cs.validation.framework.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import ro.ubbcluj.cs.validation.framework.core.ParameterName;
import ro.ubbcluj.cs.validation.framework.core.ValidationError;

public class TextValidator extends BaseValidator {

	private String[] paramValue;
	private Map<ParameterName, String> validationParameters;

	public TextValidator(String[] paramValue, Map<ParameterName, String> validationParameters) {
		this.paramValue = paramValue;
		this.validationParameters = validationParameters;
	}
	
	public List<ValidationError> validate() {
		List<ValidationError> errors = new ArrayList<ValidationError>();
		for(String value : paramValue){
			ValidationError requiredCheck = validateRequired(value, validationParameters);
			if (requiredCheck != ValidationError.NO_ERRORS) {
				errors.add(requiredCheck);
			} else {
				ValidationError minLenCheck = validateMinLength(value, validationParameters);
				ValidationError maxLenCheck = validateMaxLength(value, validationParameters);
				if (minLenCheck != ValidationError.NO_ERRORS) {
					errors.add(minLenCheck);
				}
				if (maxLenCheck != ValidationError.NO_ERRORS) {
					errors.add(maxLenCheck);
				}
			}
		}		
		return errors;
	}

	public final String[] getParamValue() {
		return paramValue;
	}

	public final void setParamValue(String[] paramValue) {
		this.paramValue = paramValue;
	}

	public final Map<ParameterName, String> getValidationParameters() {
		return validationParameters;
	}

	public final void setValidationParameters(Map<ParameterName, String> validationParameters) {
		this.validationParameters = validationParameters;
	}
}
